<template>
    <CmDialog v-model="modelValue" :dialogTitle="title" @closed="closed">
        <el-form :model="dataForm" label-width="120px" ref="ruleFormRef" :rules="rules">
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="用户ID" prop="gradeId">
                        <el-input v-model="userinfo.account" readonly placeholder="请输入" />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="充值金额" prop="storeName">
                        <el-input v-model="dataForm.money" placeholder="请输入" />
                    </el-form-item>
                </el-col>

            </el-row>

        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="closed" round>关闭</el-button>
                <el-button type="primary" @click="submitClick" round>保存</el-button>
            </span>
        </template>
    </CmDialog>
</template>
  
<script>
import CmDialog from "@/views/memberManagement/components/cmDialog.vue";
import { recharge } from "../../../api/member.js";
import { defineComponent, reactive, ref, toRefs } from "vue";
export default defineComponent({
    model: {
        prop: "visible",
        event: "closed",
    },
    components: { CmDialog },
    props: {
        visible: { type: Boolean, default: false },
        title: { type: Boolean, default: "新增会员" },
        modelValue: { type: Boolean, default: false },
        userinfo: { type: Object }
    },
    setup(props, context) {
        const state = reactive({
            dataForm: {
                money: 0
            },
            rules: {
                money: [
                    { required: true, message: "请输入金额", trigger: "blur" },
                ],
            },
        });

        const closed = () => {
            context.emit("update:modelValue", false);
        };
        const ruleFormRef = ref(null);

        return {
            ...toRefs(state),
            closed,

            ruleFormRef,
        };
    },
    created() {

    },
    methods: {
      submitClick: async function () {


            try {
                let params = {
                    id: this.userinfo.id,
                    money: this.dataForm.money
                };
                let res = await recharge({ ...params, field: this.fieldParams });
                if (res.code) {
                    this.$message({
                        message: "充值成功^_^",
                        type: "success",
                    });
                    this.closed();
                    this.$parent.search();
                }
            } catch (error) {
                console.log(error);
            }
            //  debugger;
            // this.ruleFormRef.value.validate((valid, fields) => {
            //     debugger;
            //     if (valid) {
            //         debugger;

            //     }
            // });

        },
    }
});
</script>
  